package edu.dayu.sort;

import java.util.Arrays;

/**
 * @author: dayu
 * @date: 2023/6/21 17:15
 * 选择排序
 */
public class SelectionSort {
    public static void main(String[] args) {
        int[] arr = {6,4,5,7,2,8,3,0,9,1};
        for (int i = 0; i < arr.length; i++) {
            // 记录未排序中最小数得下标。
            int temp = i;
            for (int j = i+1;j<arr.length;j++){
                if (arr[temp] > arr[j]){
                    temp = j;
                }
            }
            if (temp != i){
                int te = arr[temp];
                arr[temp] = arr[i];
                arr[i] = te;
            }
            System.out.println(Arrays.toString(arr));
        }
    }
}
